let supportsPassive = false

try {
	const opts = {}
	Object.defineProperty(opts, 'passive', {
		get () {
			supportsPassive = true
		}
	})
	window.addEventListener('test-passive', null, opts)
} catch (e) {}

export function on (target, event, handler, passive = false) {
	target.addEventListener(
		event,
		handler,
		supportsPassive ? { capture: false, passive } : false
	)
}

export function off (target, event, handler) {
	target.removeEventListener(event, handler)
}

export function stop (event) {
	event.stopPropagation()
}

export function prevent (event) {
	event.preventDefault()
}

export function getTextWidth (str) {
	const html = document.createElement('span')
	html.innerText = str
	html.className = 'fx-getTextWidth-span'
	document.querySelector('body').appendChild(html)
	const width = document.querySelector('.fx-getTextWidth-span').offsetWidth
	document.querySelector('.fx-getTextWidth-span').remove()
	return width
}
